<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from "@/utils/hooks";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    name: "",
    code: "",
    sort: 0,
    status: "NORMAL",
    description: ""
  })
});

const ruleFormRef = ref();
const { switchStyle } = usePublicHooks();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="120px"
  >
    <el-form-item label="业务域名称" prop="name">
      <el-input
        v-model="newFormInline.name"
        clearable
        placeholder="请输入业务域名称"
      />
    </el-form-item>
    <el-form-item label="业务域编码" prop="code">
      <el-input
        v-model="newFormInline.code"
        clearable
        placeholder="请输入业务域编码"
      />
    </el-form-item>
    <el-form-item label="排序">
      <el-input-number
        v-model="newFormInline.sort"
        class="!w-full"
        :min="0"
        :max="9999"
        controls-position="right"
      />
    </el-form-item>
    <el-form-item label="业务域状态">
      <el-switch
        v-model="newFormInline.status"
        inline-prompt
        active-value="NORMAL"
        inactive-value="INACTIVE"
        active-text="启用"
        inactive-text="停用"
        :style="switchStyle"
      />
    </el-form-item>
    <el-form-item label="备注">
      <el-input
        v-model="newFormInline.description"
        placeholder="请输入备注信息"
        type="textarea"
      />
    </el-form-item>
  </el-form>
</template>
